import urllib2, time, threading
from notify import notify
from gi.repository import Gtk, Gdk, GObject
def netCheck(fun, *args):
    #print args
    try:
	response=urllib2.urlopen('http://google.com',timeout=3)
	fun(*args)
	#print "connected"
    except urllib2.URLError as err: 
	#print err 
	notify('Internet connection required !','Retrying in 60 seconds')
	thread = threading.Thread(target=retryNetCheck,args=(fun ,args))
	thread.daemon = True
	thread.start()
	

def retryNetCheck(fun ,args):
	time.sleep (60)
	GObject.idle_add(netCheck,fun,*args)
	#print "reconnecting"
	
